import cx from 'classnames';
import * as React from 'react';
import Checkbox from '../../../../Checkbox';
import { prefix } from '../../../../config';
import { getPrefixCls, isArray } from '../../../../utils';
import type { EditableCell } from './type';

export interface EditableCheckboxProps extends EditableCell {
  value: any;
}
const cellPrefixCls = getPrefixCls(prefix.editableTable, 'cell');

export default function EditableRadio(props: EditableCheckboxProps) {
  const {
    align,
    columnId,
    value,
    curModalParams,
    onChange,
    onBlur,
    onClick,
    onDoubleClick,
    onMouseEnter,
    onMouseLeave,
    ...restProps
  } = props;
  const v = isArray(value) ? value : [value];
  return (
    <Checkbox.Group
      {...restProps}
      className={cx(align, `${cellPrefixCls}__component`)}
      value={v}
      onChange={(checkedValue: any[]) => {
        const value = isArray ? checkedValue : checkedValue.join('');
        onChange(value);
        onBlur(value);
      }}
    />
  );
}
